const padDate = function (value) {
    return value < 10 ? '0' + value : value;
};

export function getNowTime(value) {
    var date = new Date(value);
    var year = date.getFullYear();
    var month = padDate(date.getMonth()+1);
    var day = padDate(date.getDate());
    var hours = padDate(date.getHours());
    var minutes = padDate(date.getMinutes());
    var seconds = padDate(date.getSeconds());
    //var week = padDate(date.getDay());
    //let week = new Date(value).getDay();
    //let weeks = ["日","一","二","三","四","五","六"];
    //let getWeek = "星期" + weeks[week];
    return '' + year + month + day + hours + minutes + seconds;
    //return year + '-' + month + '-' + day +' '+'|'+' '  +getWeek;
}

// 深拷贝 公共方法
export function deepClone(source) {
    if (!source && typeof source !== 'object') {
        throw new Error("deep clone error");
    }
    const targetObj = source.constructor === Array ? [] : {}
    Object.keys(source).forEach(keys => {
        if (source[keys] && typeof source[keys] === 'object') {
            targetObj[keys] = deepClone(source[keys])
        } else {
            targetObj[keys] = source[keys]
        }
    })
    return targetObj
}

// 数组去重
export function unique(arr) {
    const res = new Map();
    return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
}
